package com.education.teacher.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.education.model.Dissent;
import com.education.model.ResultDo;
import com.education.service.DissentScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.List;

@Api(value="/api/master",description="学生成绩异议的相关操作")
@RestController
@RequestMapping("/api/master")
public class DissentScoreController {

@Reference
private DissentScoreService dis;

    @ApiOperation(notes = "/dissent/getDissent",httpMethod = "get",value = "获取对成绩有异议的学生")
    @RequestMapping(value = "/dissent/getDissent",method= RequestMethod.GET)
    public ResultDo<Object> getDissent(HttpSession session) throws Exception{
        int tid=Integer.parseInt((String) session.getAttribute("teacherId"));
       List<Dissent> list=dis.getDissent(tid);
       ResultDo<Object> resultDo=new ResultDo<Object>();
       resultDo.setResCode(0);
       resultDo.setResMsg("请求成功");
       resultDo.setResData(list);
        return resultDo;
    }

    @ApiOperation(notes = "/dissent/getDissentInfo",httpMethod = "get",value = "获取该生对这门课程的成绩异议信息")
    @RequestMapping(value = "/dissent/getDissentInfo",method = RequestMethod.GET)
    public ResultDo<Dissent> getDissentInfo(Dissent dissent) throws Exception{
        Dissent di=dis.getDissentInfo(dissent);
        ResultDo<Dissent> resultDo=new ResultDo<>();
        resultDo.setResCode(0);
        resultDo.setResMsg("请求成功");
        resultDo.setResData(di);
        return resultDo;
    }
    @ApiOperation(notes = "/dissent/deleteDissent",httpMethod = "get",value = "修改该异动状态为已处理")
    @RequestMapping(value = "/dissent/deleteDissent",method = RequestMethod.GET)
    public ResultDo<Integer> deleteDissent(Integer dissentId) throws Exception{

       int result=dis.deleteDissent(dissentId);
       ResultDo<Integer> resultDo=new ResultDo<>();
       if(result>0){
           resultDo.setResCode(0);
           resultDo.setResMsg("修改成功");
           resultDo.setResData(result);
       }else{
           resultDo.setResCode(-1);
           resultDo.setResMsg("修改失败");
       }
        return resultDo;
    }
}
